home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gcc / ixemul_src.lha / ixemul-41.0 / gnulib-soft-float / frexp.c < prev    next >
C/C++ Source or Header  |  1994-08-19  |  739b  |  50 lines

  1. #if defined(LIBC_SCCS) && !defined(lint)
  2. static char sccsid[] = "@(#)frexp.c    5.2 (Berkeley) 3/9/86";
  3. #endif LIBC_SCCS and not lint
  4.  
  5. #define KERNEL
  6. #include "ixemul.h"
  7.  
  8. /*
  9.  *    the call
  10.  *        x = frexp(arg,&exp);
  11.  *    must return a double fp quantity x which is <1.0
  12.  *    and the corresponding binary exponent "exp".
  13.  *    such that
  14.  *        arg = x*2^exp
  15.  *    if the argument is 0.0, return 0.0 mantissa and 0 exponent.
  16.  */
  17.  
  18. double
  19. frexp(double x, int *i)
  20. {
  21.   int neg;
  22.   int j;
  23.  
  24.   j = 0;
  25.   neg = 0;
  26.  
  27.   if (x < 0)
  28.     {
  29.       x = -x;
  30.       neg = 1;
  31.     }
  32.  
  33.   if (x >= 1.0)
  34.     while(x >= 1.0)
  35.       {
  36.     j = j+1;
  37.     x = x/2;
  38.       }
  39.   else if(x < 0.5 && x != 0.0)
  40.     while(x < 0.5)
  41.       {
  42.     j = j-1;
  43.     x = 2*x;
  44.       }
  45.  
  46.   *i = j;
  47.   if (neg) x = -x;
  48.   return x;
  49. }
  50.